package com.baike.myScheduler;

import com.baike.job.IncrementJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * Created by wanggenshen
 * Date: on 2018/7/7 16:31.
 * Description: XXX
 */
@Component
public class MyScheduler {

    @Autowired
    private Scheduler scheduler;

    @PostConstruct
    public void initJob() throws SchedulerException {
        //要去执行那个类  JobBuilder.newJob
        JobDetail detail = JobBuilder.newJob(IncrementJob.class).withIdentity("JOB_NAME", "JOB_GROUP").build();

        Trigger trigger = TriggerBuilder.newTrigger().withIdentity("TRIGGER_NAME", "TRIGGER_GROUP").startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0 12 * * ?")).build();
        scheduler.scheduleJob(detail, trigger);
        System.out.println("----- scheduler start ! -----");

        scheduler.start();
    }
}


